// ================================START====================================
// Template generated from		FRAMEWORKIVY CODE GENERATOR
// Generator Version:			<1.0.0.0>
// Template Creation Time:		<Saturday, 13 August, 2016   12:39:28 AM>
// Template Modification Time:	<Sunday, 4 September, 2016   12:40:01 AM>
// Code Generation Time:		<Monday, 12 September, 2016   10:01:47 PM>
// Workstation ID:				<PRAVESH>
// Current system User ID:		<pravesh>
// Entity/Table Name:			<ContentBinaryData>
// ModuleName:			        <ContentManagement>
// Description:					<CSharp Class For Entity Data Access Object>
// Template File:				<IvyGodeGenDefaultTemplate V1.1.xml>

// Please modify the generated code as per requirement.
// This code generator is just to speed up the stereo type codes
// Complex logic needs to be modified manually.

// =========================================================================
// If Code has been MANUALLY MODIFIED then set below line to TRUE
// CODE MANUALLY MODIFIED = FALSE
// =========================================================================

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

//This Class specific System namespaces
using System.Data;
using System.Data.Common;

//This Class Specific IvyFramework namespaces
using Ivy.Common.Framework.Base;
using Ivy.Common.Framework.DataAccess;

using Ivy.ContentManagement.Entity;

namespace Ivy.ContentManagement.DataAccess
{
    public class ContentBinaryDataDao : IDaoInterface<ContentBinaryData, ContentBinaryDataCriteria>
    {
        #region  Variable & constant
        // All constants and local variable should be declared here
        // TRY NOT TO CREATE PUBLIC VARIABLES INSTEAD USE PROPERTIES FOR THAT PURPOSE.
        // Variable naming convention :- 
        // The naming should be self explanatory, make it long to explain the purpose 
        // and use PascalCase to seperate words as shown in the example below.
        // DO NOT USE ANY ABBRIVIATION use full word (like "Customer" instead of "Cust"
        // Naming convention for all local variable should start with underscore "_"
        // Naming convention for all local constant should start with "_The"
        // Example :    string _CustomerCode = string.Empty;
        // Example :    const string _TheDefaultSmtpServer = "DefaultSmtpServer";
        // ==================== START YOUR CODE FROM NEXT LINE ========================

        #endregion  Variable & constant

        #region Constructor & Destructor
        // Cut and Copy the default constructor for the class inside this region.
        // Generally not required in UI layer.
        // Example:
        // public SampleClassTemplate()
        // {

        // }
        // ==================== START YOUR CODE FROM NEXT LINE ========================

        #endregion Constructor & Destructor

        #region Properties
        // Any value/variable that needs to be exposed outside the class we need to create a property.
        // Avoid creating public variables rather create public properties.
        // UI layer may have public custom properties. these are very handy for User Controls.
        // Property naming convention :- Properties will be exposed outside the class, 
        // the naming should be self explanatory, make it long to explain the purpose 
        // and use PascalCase to seperate words as shown in the example below.
        // DO NOT USE ANY ABBRIVIATION use full word (like "Customer" instead of "Cust"
        // All properties should have a corresponding local variable 
        // and the property name and local variable name should match.
        // Example :
        // public string CustomerCode
        // {
        //     get
        //     {
        //         return _CustomerCode;
        //     }
        //     set
        //     {
        //         _CustomerCode = value;
        //     }
        // }
        // ==================== START YOUR CODE FROM NEXT LINE ========================

        #endregion Properties

        #region Events
        // Generally UI layer will have public events.
        // Cut and Copy the default generated events for the class inside this region.
        // ==================== START YOUR CODE FROM NEXT LINE ========================

        #endregion Events

        #region Public Methods
        
        #region IDaoInterface<ContentBinaryData, ContentBinaryDataCriteria> Members
        // All the default methods mentioned in the Interface IDaoInterface<ContentBinaryData> is to be implemented here
        // ==================== START YOUR CODE FROM NEXT LINE ========================
        
        /// <summary>
        /// IDaoInterface INSERT method is used to insert new record in the Database
        /// The parameter is an instance of an EntityObject filled with valid properties/attributes/Field values.
        /// Most of the time the PrimaryKey is an AutoGenerated value, which is left Empty/NULL 
        /// and filled once a new record is generated in the Database, through the output parameter.
        /// DO NOTE that 
        /// "Sys_OrganizationID" should not be empty and
        /// "Sys_CreatedByID" should not be empty
        /// </summary>
        /// <param name="ContentBinaryData"></param>
        /// <returns></returns>
        public bool Insert(ContentBinaryData ContentBinaryDataEntity)
        {
            bool IsOperationSuccessful = false;

            //For INSERTING new <ContentBinaryData> entity data to database, [EntityState] attribute should be [New]
            if (ContentBinaryDataEntity.EntityState == Common.Framework.Base.EntityState.New)
            {
                DbConnection DbConn = DataAccessProviderUtility.CreateConnectionWithConnectionString();
                DbCommand CmdObj = DataAccessProviderUtility.CreateCommand();
                CmdObj.CommandText = "Ivy_ContentManagement_ContentBinaryData_Insert";
                CmdObj.CommandType = CommandType.StoredProcedure;

                //INPUT PARAMETERS FOR STORED PROCEDURE
                //Always use a private TRANSALATE method transfer data from EntityObject to Database CommandObj parameters
                TranslateContentBinaryDataFromEntityToDatabaseParameters(CmdObj, ContentBinaryDataEntity);

                //OUTPUT PARAMETERS DEFAULT VALUE FOR STORED PROCEDURE
                //If any Field IS AUTO GENERATED, it has been declared as OUTPUT parameter in STORED PROCEDURE and should be declared below
                DataAccessProviderUtility.AddParameter(CmdObj, "@ContentBinaryDataKey", ParameterDirection.Output, DbType.Int32, DBNull.Value);

                //OUTPUT parameter is needed to get Server datetime of the record update
                DataAccessProviderUtility.AddParameter(CmdObj, "@Sys_DateOfCreation", ParameterDirection.Output, DbType.DateTime, DBNull.Value);

                CmdObj.Connection = DbConn;
                DbConn.Open();
                CmdObj.Prepare();
                int _NoOfRecords = CmdObj.ExecuteNonQuery();

                //Check if any record is effected as a result of Record Insert
                if (_NoOfRecords > 0)
                {
                    //OUTPUT PARAMETERS FOR STORED PROCEDURE
                    //If any Field is AUTO GENERATED, it should be declared as OUTPUT parameter to be initialized with the newly generated value
                    ContentBinaryDataEntity.ContentBinaryDataKey = Convert.ToInt32(CmdObj.Parameters["@ContentBinaryDataKey"].Value);

                    //OUTPUT parameter "Sys_DateOfCreation" is initialized with Sever datetime of the record update
                    ContentBinaryDataEntity.Sys_DateOfCreation = Convert.ToDateTime(CmdObj.Parameters["@Sys_DateOfCreation"].Value);

                    //When new record is inserted "Sys_DateOfModification" should be same as "Sys_DateOfCreation"
                    ContentBinaryDataEntity.Sys_DateOfModification = ContentBinaryDataEntity.Sys_DateOfCreation;
                    //Once record is Saved in the Database "EntityState" should be set to "[UnChanged]"
                    ContentBinaryDataEntity.EntityState = EntityState.UnChanged;
                    IsOperationSuccessful = true;
                }
                CmdObj.Dispose();
                DbConn.Close();
            }
            else
            {
                throw new Exception("For INSERTING new <ContentBinaryData> entity data to database, [EntityState] attribute should be [New]");
            }

            return IsOperationSuccessful;
        }

        /// <summary>
        /// IDaoInterface UPDATE method is used to Update existing record in the Database
        /// The parameter is an instance of an EntityObject filled with valid properties/attributes/Field values.
        /// DO NOTE that 
        /// "Sys_OrganizationID" should not be empty and
        /// "Sys_ModifiedByID" should not be empty
        /// </summary>
        /// <param name="ContentBinaryData"></param>
        /// <returns></returns>
        public bool Update(ContentBinaryData ContentBinaryDataEntity)
        {
            bool IsOperationSuccessful = false;

            //For UPDATING existing <ContentBinaryData> entity data to database, [EntityState] attribute should be [Changed]
            if (ContentBinaryDataEntity.EntityState == Common.Framework.Base.EntityState.Changed)
            {
                DbConnection DbConn = DataAccessProviderUtility.CreateConnectionWithConnectionString();
                DbCommand CmdObj = DataAccessProviderUtility.CreateCommand();
                CmdObj.CommandText = "Ivy_ContentManagement_ContentBinaryData_Update";
                CmdObj.CommandType = CommandType.StoredProcedure;

                //INPUT PARAMETERS FOR STORED PROCEDURE
                //Most of the input parameters for STORED PROCEDURE are taken care by TranslateContentBinaryDataFromEntityToDatabaseParameters() method. 
                //But AUTO GENERATED fields are excluded from TranslateContentBinaryDataFromEntityToDatabaseParameters() method. 
                //However any PRIMARY KEY fields which are not AUTO GENERATED fields are going to be initialized below as INPUT parameter, 
                //since all PRIMARY KEYS are required for WHERE clause in STORED PROCEDURE to UPDATE a specific record.
                DataAccessProviderUtility.AddParameter(CmdObj, "@ContentBinaryDataKey", ParameterDirection.Input, DbType.Int32, ContentBinaryDataEntity.ContentBinaryDataKey);

                //Always use a private TRANSALATE method transfer data from EntityObject to Database CommandObj parameters
                TranslateContentBinaryDataFromEntityToDatabaseParameters(CmdObj, ContentBinaryDataEntity);
                
                //OUTPUT PARAMETERS DEFAULT VALUE FOR STORED PROCEDURE
                //OUTPUT parameter is needed to get Server datetime of the record update
                DataAccessProviderUtility.AddParameter(CmdObj, "@Sys_DateOfModification", ParameterDirection.Output, DbType.DateTime, DBNull.Value);

                CmdObj.Connection = DbConn;
                DbConn.Open();
                CmdObj.Prepare();
                int _NoOfRecords = CmdObj.ExecuteNonQuery();

                //Check if any record is effected as a result of Record Update
                if (_NoOfRecords > 0)
                {
                    //OUTPUT PARAMETERS FOR STORED PROCEDURE
                    //OUTPUT parameter "Sys_DateOfModification" is initialized with Sever datetime of the record update
                    ContentBinaryDataEntity.Sys_DateOfModification = Convert.ToDateTime(CmdObj.Parameters["@Sys_DateOfModification"].Value);

                    //Once record is Saved in the Database "EntityState" should be set to "[UnChanged]"
                    ContentBinaryDataEntity.EntityState = EntityState.UnChanged;
                    IsOperationSuccessful = true;
                }
                CmdObj.Dispose();
                DbConn.Close();
            }
            else
            {
                throw new Exception("For UPDATING existing <ContentBinaryData> entity data to database, [EntityState] attribute should be [Changed]");
            }

            return IsOperationSuccessful;
        }
                
        /// <summary>
        /// IDaoInterface DELETE method is used to remove existing record from the Database. The record will be physically removed.
        /// The parameter is an instance of an EntityObject filled with valid properties/attributes/Field values.
        /// Most of the time the EntityPrimaryKey is a single Field/Column, 
        /// Incase of composite PrimaryKeys with multiple Fields/Columns to represent a PrimaryKey,
        /// DO NOTE that 
        /// "Sys_OrganizationID" should not be empty 
        /// </summary>
        /// <param name="ContentBinaryData"></param>
        /// <returns></returns>
        public bool Delete(ContentBinaryData ContentBinaryDataEntity)
        {
            //THIS METHOD MAY NOT BE IMPLEMENTED. by REMOVING the below code and REPLACING it with "throw new NotImplementedException();"
            
            throw new NotImplementedException();
        }

        /// <summary>
        /// IDaoInterface GET_BY_ID method is used to Retrive a SINGLE existing record from Database and converts data to an instance of the EntityObject
        /// Most of the time the EntityPrimaryKey is a single Field/Column, 
        /// Incase of composite PrimaryKeys with multiple Fields/Columns to represent a PrimaryKey,
        /// THIS METHOD MAY NOT BE IMPLEMENTED. by using "throw new NotImplementedException();"
        /// </summary>
        /// <param name="ID"></param>
        /// <returns>ContentBinaryData</returns>
        public ContentBinaryData GetByID(string ID)
        {
            //THIS METHOD MAY NOT BE IMPLEMENTED. by REMOVING the below code and REPLACING it with "throw new NotImplementedException();"
            
            throw new NotImplementedException();

        }
        /// <summary>
        /// IDaoInterface GETALL method is used to Retrive a Collection of existing records from Database and converts data to an instance of the EntityObject LIST
        /// Incase we need Filter parameter for the RETRIVING the collection,
        /// THIS METHOD MAY NOT BE IMPLEMENTED. by using "throw new NotImplementedException();"
        /// </summary>
        /// <returns>List<ContentBinaryData></returns> 
        public List<ContentBinaryData> GetAll()
        {
            //THIS METHOD MAY NOT BE IMPLEMENTED. by REMOVING the below code and REPLACING it with "throw new NotImplementedException();"
            
            //throw new NotImplementedException();

            List<ContentBinaryData> _ContentBinaryDataEntityList = new List<ContentBinaryData>();

            DbConnection DbConn = DataAccessProviderUtility.CreateConnectionWithConnectionString();
            DbCommand CmdObj = DataAccessProviderUtility.CreateCommand();
            CmdObj.CommandText = "Ivy_ContentManagement_ContentBinaryData_GetAll";
            CmdObj.CommandType = CommandType.StoredProcedure;

            
            //INPUT PARAMETERS FOR STORED PROCEDURE
            //The GetAll STORED PROC should have the below parameters
            DataAccessProviderUtility.AddParameter(CmdObj, "@Sys_IsDeleted", ParameterDirection.Input, DbType.Boolean, DBNull.Value);
            DataAccessProviderUtility.AddParameter(CmdObj, "@Sys_OrganizationID", ParameterDirection.Input, DbType.Int32, DBNull.Value);
            
            CmdObj.Connection = DbConn;
            DbConn.Open();
            CmdObj.Prepare();

            DbDataReader _DataReader = CmdObj.ExecuteReader();
            if (_DataReader.HasRows)
            {
                while (_DataReader.Read())
                {
                    ContentBinaryData _tempContentBinaryDataEntity = new ContentBinaryData(); //IMPORTANT NOTE:- Create instance only when required.
                    //Always use a private TRANSALATE method transfer data from DataReader fields to an instance of EntityObject
                    this.TranslateContentBinaryDataFieldsFromReaderToEntity(_tempContentBinaryDataEntity, _DataReader);
                    _ContentBinaryDataEntityList.Add(_tempContentBinaryDataEntity);
                }
            }
            CmdObj.Dispose();
            DbConn.Close();

            return _ContentBinaryDataEntityList;
        }
        /// <summary>
        /// IDaoInterface GETBYCRITERIA method is used to Retrive a Collection of existing records from Database and converts data to an instance of the EntityObject LIST
        /// where we need Filter parameter for the RETRIVING the collection,
        /// THIS METHOD MAY NOT BE IMPLEMENTED. by using "throw new NotImplementedException();"
        /// </summary>
        /// <param name="ContentBinaryDataCriteriaEntity"></param>
        /// <returns></returns>
        public List<ContentBinaryData> GetByCriteria(ContentBinaryDataCriteria ContentBinaryDataCriteriaEntity)
        {
            //THIS METHOD MAY NOT BE IMPLEMENTED. by REMOVING the below code and REPLACING it with "throw new NotImplementedException();"
            
            //throw new NotImplementedException();

            List<ContentBinaryData> _ContentBinaryDataEntityList = new List<ContentBinaryData>();

            DbConnection DbConn = DataAccessProviderUtility.CreateConnectionWithConnectionString();
            DbCommand CmdObj = DataAccessProviderUtility.CreateCommand();
            CmdObj.CommandText = "Ivy_ContentManagement_ContentBinaryData_GetAllByCriteria";
            CmdObj.CommandType = CommandType.StoredProcedure;

            //INPUT PARAMETERS FOR STORED PROCEDURE WHERE Clauses From Criteria Objkect
            TranslateContentBinaryDataCriteriaFromCriteriaEntityToDatabaseParameters(CmdObj, ContentBinaryDataCriteriaEntity);

            CmdObj.Connection = DbConn;
            DbConn.Open();
            CmdObj.Prepare();

            DbDataReader _DataReader = CmdObj.ExecuteReader();
            if (_DataReader.HasRows)
            {
                while (_DataReader.Read())
                {
                    ContentBinaryData _tempContentBinaryDataEntity = new ContentBinaryData(); //IMPORTANT NOTE:- Create instance only when required.
                    //Always use a private TRANSALATE method transfer data from DataReader fields to an instance of EntityObject
                    this.TranslateContentBinaryDataFieldsFromReaderToEntity(_tempContentBinaryDataEntity, _DataReader);
                    _ContentBinaryDataEntityList.Add(_tempContentBinaryDataEntity);
                }
            }
            CmdObj.Dispose();
            DbConn.Close();

            return _ContentBinaryDataEntityList;
        }
        #endregion IDaoInterface<ContentBinaryData, ContentBinaryDataCriteria>

        // Any method that needs to be exposed outside the class will be created inside this region.
        // Public Method naming convention :- Public Method will be exposed outside the class, 
        // The input and output parameters are also going to be exposed outside the class
        // the naming should be self explanatory, make it long to explain the purpose 
        // and use PascalCase to seperate words as shown in the example below.
        // DO NOT USE ANY ABBRIVIATION use full word (like "Customer" instead of "Cust"
        // Example :
        // public bool RegisterNewCustomer(Customer Customer)
        // {
        //     bool IsCustomerDataSaved = false;
        //     //TO DO logic to save data
        //     IsCustomerDataSaved = InsertCustomerDataUsingDao(Customer);
        //     return IsCustomerDataSaved;
        // }
        // ==================== START YOUR CODE FROM NEXT LINE ========================
        /// <summary>
        /// IDaoInterface GET_BY_PRIMARY_KEY method is used to Retrive a SINGLE existing record from Database and converts data to an instance of the EntityObject
        /// Most of the time the EntityPrimaryKey is a single Field/Column, 
        /// Incase of composite PrimaryKeys with multiple Fields/Columns to represent a PrimaryKey,
        /// THIS METHOD MAY NOT BE IMPLEMENTED. by using "throw new NotImplementedException();"
        /// </summary>
        /// <param name="PersonKey"></param>
        /// <returns></returns>
        public ContentBinaryData GetByPrimaryKey(int ContentBinaryDataKey, int ContentKey) 
        {
            ContentBinaryData _SelectedContentBinaryDataEntity = null;

            DbConnection DbConn = DataAccessProviderUtility.CreateConnectionWithConnectionString();
            DbCommand CmdObj = DataAccessProviderUtility.CreateCommand();
            CmdObj.CommandText = "Ivy_ContentManagement_ContentBinaryData_GetByID";
            CmdObj.CommandType = CommandType.StoredProcedure;

            //INPUT PARAMETERS FOR STORED PROCEDURE WHERE Clauses
            DataAccessProviderUtility.AddParameter(CmdObj, "@ContentBinaryDataKey", ParameterDirection.Input, DbType.Int32, (ContentBinaryDataKey));
            DataAccessProviderUtility.AddParameter(CmdObj, "@ContentKey", ParameterDirection.Input, DbType.Int32, (ContentKey));

            CmdObj.Connection = DbConn;
            DbConn.Open();
            CmdObj.Prepare();
            DbDataReader _DataReader = CmdObj.ExecuteReader();

            if (_DataReader.HasRows)
            {
                if (_DataReader.Read())
                {
                    _SelectedContentBinaryDataEntity = new ContentBinaryData();
                    //Always use a private TRANSALATE method transfer data from DataReader fields to an instance of EntityObject
                    TranslateContentBinaryDataFieldsFromReaderToEntity(_SelectedContentBinaryDataEntity, _DataReader);
                }
            }

            return _SelectedContentBinaryDataEntity;

        }
        /// <summary>
        /// IDaoInterface GETALL method with "IsNotDeletedOnly" parameter is used to Retrive a Collection of existing records from Database and converts data to an instance of the EntityObject LIST
        /// The "IsNotDeletedOnly" input flag is used when the Table may hold record which has been "SOFT DELETED" 
        /// THIS METHOD MAY NOT BE IMPLEMENTED. by using "throw new NotImplementedException();"
        /// </summary>
        /// <param name="IsNotDeletedOnly"></param>
        /// <returns></returns>
        public List<ContentBinaryData> GetAll(bool IsNotDeletedOnly)
        {
            //THIS METHOD MAY NOT BE IMPLEMENTED. by REMOVING the below code and REPLACING it with "throw new NotImplementedException();"
            
            //throw new NotImplementedException();

            List<ContentBinaryData> _ContentBinaryDataEntityList = new List<ContentBinaryData>();

            DbConnection DbConn = DataAccessProviderUtility.CreateConnectionWithConnectionString();
            DbCommand CmdObj = DataAccessProviderUtility.CreateCommand();
            CmdObj.CommandText = "Ivy_ContentManagement_ContentBinaryData_GetAll";
            CmdObj.CommandType = CommandType.StoredProcedure;
            
            //INPUT PARAMETERS FOR STORED PROCEDURE
            //The GetAll STORED PROC should have the below parameters
            DataAccessProviderUtility.AddParameter(CmdObj, "@Sys_IsDeleted", ParameterDirection.Input, DbType.Boolean, (!IsNotDeletedOnly));
            DataAccessProviderUtility.AddParameter(CmdObj, "@Sys_OrganizationID", ParameterDirection.Input, DbType.Int32, DBNull.Value);
            
            CmdObj.Connection = DbConn;
            DbConn.Open();
            CmdObj.Prepare();

            DbDataReader _DataReader = CmdObj.ExecuteReader();
            if (_DataReader.HasRows)
            {
                while (_DataReader.Read())
                {
                    ContentBinaryData _tempContentBinaryDataEntity = new ContentBinaryData(); //IMPORTANT NOTE:- Create instance only when required.
                    //Always use a private TRANSALATE method transfer data from DataReader fields to an instance of EntityObject
                    this.TranslateContentBinaryDataFieldsFromReaderToEntity(_tempContentBinaryDataEntity, _DataReader);
                    _ContentBinaryDataEntityList.Add(_tempContentBinaryDataEntity);
                }
            }
            CmdObj.Dispose();
            DbConn.Close();

            return _ContentBinaryDataEntityList;
        }
        /// <summary>
        /// IDaoInterface GETALL method with "OrganizationID" parameter is used to Retrive a Collection of existing records from Database and converts data to an instance of the EntityObject LIST
        /// The "OrganizationID" input parameter is used when the Table is holding Records for more than one Organization (SaaS Model) 
        /// THIS METHOD MAY NOT BE IMPLEMENTED. by using "throw new NotImplementedException();"
        /// </summary>
        /// <param name="OrganizationID"></param>
        /// <returns></returns>
        public List<ContentBinaryData> GetAll(int OrganizationID)
        {
            //THIS METHOD MAY NOT BE IMPLEMENTED. by REMOVING the below code and REPLACING it with "throw new NotImplementedException();"
            
            //throw new NotImplementedException();

            List<ContentBinaryData> _ContentBinaryDataEntityList = new List<ContentBinaryData>();

            DbConnection DbConn = DataAccessProviderUtility.CreateConnectionWithConnectionString();
            DbCommand CmdObj = DataAccessProviderUtility.CreateCommand();
            CmdObj.CommandText = "Ivy_ContentManagement_ContentBinaryData_GetAll";
            CmdObj.CommandType = CommandType.StoredProcedure;
            
            //INPUT PARAMETERS FOR STORED PROCEDURE
            //The GetAll STORED PROC should have the below parameters
            DataAccessProviderUtility.AddParameter(CmdObj, "@Sys_IsDeleted", ParameterDirection.Input, DbType.Boolean, DBNull.Value);
            DataAccessProviderUtility.AddParameter(CmdObj, "@Sys_OrganizationID", ParameterDirection.Input, DbType.Int32, (OrganizationID));
            
            CmdObj.Connection = DbConn;
            DbConn.Open();
            CmdObj.Prepare();

            DbDataReader _DataReader = CmdObj.ExecuteReader();
            if (_DataReader.HasRows)
            {
                while (_DataReader.Read())
                {
                    ContentBinaryData _tempContentBinaryDataEntity = new ContentBinaryData(); //IMPORTANT NOTE:- Create instance only when required.
                    //Always use a private TRANSALATE method transfer data from DataReader fields to an instance of EntityObject
                    this.TranslateContentBinaryDataFieldsFromReaderToEntity(_tempContentBinaryDataEntity, _DataReader);
                    _ContentBinaryDataEntityList.Add(_tempContentBinaryDataEntity);
                }
            }
            CmdObj.Dispose();
            DbConn.Close();

            return _ContentBinaryDataEntityList;
        }
        /// <summary>
        /// IDaoInterface GETALL method with "IsNotDeletedOnly" & "OrganizationID" parameter is used to Retrive a Collection of existing records from Database and converts data to an instance of the EntityObject LIST
        /// The "IsNotDeletedOnly" input flag is used when the Table may hold record which has been "SOFT DELETED" and
        /// The "OrganizationID" input parameter is used when the Table is holding Records for more than one Organization (SaaS Model) 
        /// THIS METHOD MAY NOT BE IMPLEMENTED. by using "throw new NotImplementedException();"
        /// </summary>
        /// <param name="IsNotDeletedOnly"></param>
        /// <param name="OrganizationID"></param>
        /// <returns></returns>
        public List<ContentBinaryData> GetAll(bool IsNotDeletedOnly, int OrganizationID)
        {
            //THIS METHOD MAY NOT BE IMPLEMENTED. by REMOVING the below code and REPLACING it with "throw new NotImplementedException();"
            
            //throw new NotImplementedException();

            List<ContentBinaryData> _ContentBinaryDataEntityList = new List<ContentBinaryData>();

            DbConnection DbConn = DataAccessProviderUtility.CreateConnectionWithConnectionString();
            DbCommand CmdObj = DataAccessProviderUtility.CreateCommand();
            CmdObj.CommandText = "Ivy_ContentManagement_ContentBinaryData_GetAll";
            CmdObj.CommandType = CommandType.StoredProcedure;
            
            //INPUT PARAMETERS FOR STORED PROCEDURE
            //The GetAll STORED PROC should have the below parameters
            DataAccessProviderUtility.AddParameter(CmdObj, "@Sys_IsDeleted", ParameterDirection.Input, DbType.Boolean, (!IsNotDeletedOnly));
            DataAccessProviderUtility.AddParameter(CmdObj, "@Sys_OrganizationID", ParameterDirection.Input, DbType.Int32, (OrganizationID));
            
            CmdObj.Connection = DbConn;
            DbConn.Open();
            CmdObj.Prepare();

            DbDataReader _DataReader = CmdObj.ExecuteReader();
            if (_DataReader.HasRows)
            {
                while (_DataReader.Read())
                {
                    ContentBinaryData _tempContentBinaryDataEntity = new ContentBinaryData(); //IMPORTANT NOTE:- Create instance only when required.
                    //Always use a private TRANSALATE method transfer data from DataReader fields to an instance of EntityObject
                    this.TranslateContentBinaryDataFieldsFromReaderToEntity(_tempContentBinaryDataEntity, _DataReader);
                    _ContentBinaryDataEntityList.Add(_tempContentBinaryDataEntity);
                }
            }
            CmdObj.Dispose();
            DbConn.Close();

            return _ContentBinaryDataEntityList;
        }
        #endregion Public Methods

        #region Private Methods
        // All local class level methods will be inside this region. Mostly these are helper methods.
        // Private Method naming convention :- The naming should be self explanatory, 
        // make it long to explain the purpose and use PascalCase to seperate words as shown in the example below.
        // DO NOT USE ANY ABBRIVIATION use full word (like "Customer" instead of "Cust"
        // Input parameter will have a "p" as prefix. 
        // This will help the parameter variable that the value is originated outside this private method.
        // Example :
        // public bool InsertCustomerDataUsingDao(Customer pCustomer)
        // {
        //     bool IsCustomerDataInsertedSuccessfully = false;
        //     //TO DO logic to save data
        //     //....
        //     //....
        //     return IsCustomerDataInsertedSuccessfully;
        // }
        // ==================== START YOUR CODE FROM NEXT LINE ========================

        private void TranslateContentBinaryDataFromEntityToDatabaseParameters(DbCommand pDbCommand, ContentBinaryData pContentBinaryData)
        {
            DataAccessProviderUtility.AddParameter(pDbCommand, "@ContentKey", ParameterDirection.Input, DbType.Int32, pContentBinaryData.ContentKey);
            DataAccessProviderUtility.AddParameter(pDbCommand, "@ContentBinaryData", ParameterDirection.Input, DbType.Binary, pContentBinaryData.ContentBinaryData);
            DataAccessProviderUtility.AddParameter(pDbCommand, "@ContentThumbnailImage", ParameterDirection.Input, DbType.Binary, pContentBinaryData.ContentThumbnailImage);
            DataAccessProviderUtility.AddParameter(pDbCommand, "@ContentBinaryDataFileName", ParameterDirection.Input, DbType.String, pContentBinaryData.ContentBinaryDataFileName);
            DataAccessProviderUtility.AddParameter(pDbCommand, "@ContentBinaryDataType", ParameterDirection.Input, DbType.String, pContentBinaryData.ContentBinaryDataType);
            if (pContentBinaryData.ContentTotalDownloads != null)
            {
                DataAccessProviderUtility.AddParameter(pDbCommand, "@ContentTotalDownloads", ParameterDirection.Input, DbType.Int32, pContentBinaryData.ContentTotalDownloads);
            }
            else
            {
                DataAccessProviderUtility.AddParameter(pDbCommand, "@ContentTotalDownloads", ParameterDirection.Input, DbType.Int32, DBNull.Value);
            }

            //Always use this Base Class method to populate "Sys_xxxxxx" parameters for the Entity
            if (pContentBinaryData.EntityState == EntityState.New) //Check if this is insert action
            {
                DatabaseCommon.InsertStoredProcForParameterDatEntityBase(pDbCommand, pContentBinaryData);
            }
            if (pContentBinaryData.EntityState == EntityState.Changed) //Check if this update action
            {
                DataAccessProviderUtility.AddParameter(pDbCommand, "@ConcurrencyTimeStamp", ParameterDirection.Input, DbType.DateTime, pContentBinaryData.ConcurrencyTimeStamp);
                DatabaseCommon.UpdateStoredProcForParameterDatEntityBase(pDbCommand, pContentBinaryData);
            }
        }
        private void TranslateContentBinaryDataCriteriaFromCriteriaEntityToDatabaseParameters(DbCommand pDbCommand, ContentBinaryDataCriteria pContentBinaryDataCriteria)
        {
            DataAccessProviderUtility.AddParameter(pDbCommand, "@ContentBinaryDataKey", ParameterDirection.Input, DbType.Int32, pContentBinaryDataCriteria.ContentBinaryDataKey);
            DataAccessProviderUtility.AddParameter(pDbCommand, "@ContentKey", ParameterDirection.Input, DbType.Int32, pContentBinaryDataCriteria.ContentKey);
            //As Criteria Entity is used for search parameters. 
            //Binary data type should not be part of search parameter. 
            //Attribute [ContentBinaryDataCriteria.ContentBinaryData] is not generated in Criteria Entity. 
            //DataAccessProviderUtility.AddParameter(pDbCommand, "@ContentBinaryData", ParameterDirection.Input, DbType.Binary, pContentBinaryDataCriteria.ContentBinaryData);

            //As Criteria Entity is used for search parameters. 
            //Binary data type should not be part of search parameter. 
            //Attribute [ContentBinaryDataCriteria.ContentThumbnailImage] is not generated in Criteria Entity. 
            //DataAccessProviderUtility.AddParameter(pDbCommand, "@ContentThumbnailImage", ParameterDirection.Input, DbType.Binary, pContentBinaryDataCriteria.ContentThumbnailImage);

            if (pContentBinaryDataCriteria.ContentBinaryDataFileName != string.Empty)
            {
                DataAccessProviderUtility.AddParameter(pDbCommand, "@ContentBinaryDataFileName", ParameterDirection.Input, DbType.String, pContentBinaryDataCriteria.ContentBinaryDataFileName);
            }
            else
            {
                DataAccessProviderUtility.AddParameter(pDbCommand, "@ContentBinaryDataFileName", ParameterDirection.Input, DbType.String, DBNull.Value);
            }
            if (pContentBinaryDataCriteria.ContentBinaryDataType != string.Empty)
            {
                DataAccessProviderUtility.AddParameter(pDbCommand, "@ContentBinaryDataType", ParameterDirection.Input, DbType.String, pContentBinaryDataCriteria.ContentBinaryDataType);
            }
            else
            {
                DataAccessProviderUtility.AddParameter(pDbCommand, "@ContentBinaryDataType", ParameterDirection.Input, DbType.String, DBNull.Value);
            }
            if (pContentBinaryDataCriteria.ContentTotalDownloads != null)
            {
                DataAccessProviderUtility.AddParameter(pDbCommand, "@ContentTotalDownloads", ParameterDirection.Input, DbType.Int32, pContentBinaryDataCriteria.ContentTotalDownloads);
            }
            else
            {
                DataAccessProviderUtility.AddParameter(pDbCommand, "@ContentTotalDownloads", ParameterDirection.Input, DbType.Int32, DBNull.Value);
            }

            // Sys_xxxx Columns
            if (pContentBinaryDataCriteria.Sys_DateOfCreation != null)
            {
                DataAccessProviderUtility.AddParameter(pDbCommand, "@Sys_DateOfCreation", ParameterDirection.Input, DbType.DateTime, pContentBinaryDataCriteria.Sys_DateOfCreation);
            }
            else
            {
                DataAccessProviderUtility.AddParameter(pDbCommand, "@Sys_DateOfCreation", ParameterDirection.Input, DbType.DateTime, DBNull.Value);
            }
            if (pContentBinaryDataCriteria.Sys_DateOfModification != null)
            {
                DataAccessProviderUtility.AddParameter(pDbCommand, "@Sys_DateOfModification", ParameterDirection.Input, DbType.DateTime, pContentBinaryDataCriteria.Sys_DateOfModification);
            }
            else
            {
                DataAccessProviderUtility.AddParameter(pDbCommand, "@Sys_DateOfModification", ParameterDirection.Input, DbType.DateTime, DBNull.Value);
            }
            if (pContentBinaryDataCriteria.Sys_CreatedByID != string.Empty)
            {
                DataAccessProviderUtility.AddParameter(pDbCommand, "@Sys_CreatedByID", ParameterDirection.Input, DbType.String, pContentBinaryDataCriteria.Sys_CreatedByID);
            }
            else
            {
                DataAccessProviderUtility.AddParameter(pDbCommand, "@Sys_CreatedByID", ParameterDirection.Input, DbType.String, DBNull.Value);
            }
            if (pContentBinaryDataCriteria.Sys_ModifiedByID != string.Empty)
            {
                DataAccessProviderUtility.AddParameter(pDbCommand, "@Sys_ModifiedByID", ParameterDirection.Input, DbType.String, pContentBinaryDataCriteria.Sys_ModifiedByID);
            }
            else
            {
                DataAccessProviderUtility.AddParameter(pDbCommand, "@Sys_ModifiedByID", ParameterDirection.Input, DbType.String, DBNull.Value);
            }
            if (pContentBinaryDataCriteria.Sys_DeleteType != null)
            {
                DataAccessProviderUtility.AddParameter(pDbCommand, "@Sys_DeleteType", ParameterDirection.Input, DbType.Int32, pContentBinaryDataCriteria.Sys_DeleteType);
            }
            else
            {
                DataAccessProviderUtility.AddParameter(pDbCommand, "@Sys_DeleteType", ParameterDirection.Input, DbType.Int32, DBNull.Value);
            }
            if (pContentBinaryDataCriteria.Sys_IsDeleted != null)
            {
                DataAccessProviderUtility.AddParameter(pDbCommand, "@Sys_IsDeleted", ParameterDirection.Input, DbType.Boolean, pContentBinaryDataCriteria.Sys_IsDeleted);
            }
            else
            {
                DataAccessProviderUtility.AddParameter(pDbCommand, "@Sys_IsDeleted", ParameterDirection.Input, DbType.Boolean, DBNull.Value);
            }
            if (pContentBinaryDataCriteria.Sys_OrganizationID != null)
            {
                DataAccessProviderUtility.AddParameter(pDbCommand, "@Sys_OrganizationID", ParameterDirection.Input, DbType.Int32, pContentBinaryDataCriteria.Sys_OrganizationID);
            }
            else
            {
                DataAccessProviderUtility.AddParameter(pDbCommand, "@Sys_OrganizationID", ParameterDirection.Input, DbType.Int32, DBNull.Value);
            }
            if (pContentBinaryDataCriteria.Sys_InitialPrimaryKeys != string.Empty)
            {
                DataAccessProviderUtility.AddParameter(pDbCommand, "@Sys_InitialPrimaryKeys", ParameterDirection.Input, DbType.String, pContentBinaryDataCriteria.Sys_InitialPrimaryKeys);
            }
            else
            {
                DataAccessProviderUtility.AddParameter(pDbCommand, "@Sys_InitialPrimaryKeys", ParameterDirection.Input, DbType.String, DBNull.Value);
            }
            if (pContentBinaryDataCriteria.Sys_WorkstationName != string.Empty)
            {
                DataAccessProviderUtility.AddParameter(pDbCommand, "@Sys_WorkstationName", ParameterDirection.Input, DbType.String, pContentBinaryDataCriteria.Sys_WorkstationName);
            }
            else
            {
                DataAccessProviderUtility.AddParameter(pDbCommand, "@Sys_WorkstationName", ParameterDirection.Input, DbType.String, DBNull.Value);
            }
            ////Always use this Base Class method to populate "Sys_xxxxxx" parameters for the Entity
            //if (pContentBinaryData.EntityState == EntityState.New) //Check if this is insert action
            //{
            //    DatabaseCommon.InsertStoredProcForParameterDatEntityBase(pDbCommand, pContentBinaryData);
            //}
            //if (pContentBinaryData.EntityState == EntityState.Changed) //Check if this update action
            //{
            //    DataAccessProviderUtility.AddParameter(pDbCommand, "@ConcurrencyTimeStamp", ParameterDirection.Input, DbType.DateTime, pEntityObject.ConcurrencyTimeStamp);
            //    DatabaseCommon.UpdateStoredProcForParameterDatEntityBase(pDbCommand, pContentBinaryData);
            //}
        }
        private void TranslateContentBinaryDataFieldsFromReaderToEntity(ContentBinaryData pContentBinaryData, DbDataReader pDbDataReader)
        {
            pContentBinaryData.ContentBinaryDataKey = Convert.ToInt32(pDbDataReader["ContentBinaryDataKey"]);
            pContentBinaryData.ContentKey = Convert.ToInt32(pDbDataReader["ContentKey"]);
            pContentBinaryData.ContentBinaryData = (Byte[])(pDbDataReader["ContentBinaryData"]);
            pContentBinaryData.ContentThumbnailImage = (Byte[])(pDbDataReader["ContentThumbnailImage"]);
            pContentBinaryData.ContentBinaryDataFileName = Convert.ToString(pDbDataReader["ContentBinaryDataFileName"]);
            pContentBinaryData.ContentBinaryDataType = Convert.ToString(pDbDataReader["ContentBinaryDataType"]);
            if (pDbDataReader["ContentTotalDownloads"] != DBNull.Value)
            {
            pContentBinaryData.ContentTotalDownloads = Convert.ToInt32(pDbDataReader["ContentTotalDownloads"]);
            }

            //Always use this Base Class method to populate Entity properties/Attributes "Sys_xxxxxx" with DataReader Fields/Columns
            DatabaseCommon.TranslateSystemFieldsFromReaderToEntity(pContentBinaryData, pDbDataReader);
        }
        #endregion Private Methods
    }
}


